package com.chenfan.ccp.common.exception;


import com.chenfan.ccp.common.result.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @className: GlobalExceptionHandler
 * @description: 全局异常处理类
 * @author: Leo
 * @date: 2021/1/9 5:11 下午
 **/
@RestControllerAdvice
public class CommonExceptionHandler {

    private static final Logger logger = LoggerFactory.getLogger(CommonExceptionHandler.class);
    /**
     * 类捕获 500 异常处理
     */
    @ExceptionHandler(value = Throwable.class)
    public R handlerException(Throwable e) {
        logger.error("未知异常",e);
        return R.fail();
    }

    /**
     * BusinessException 类捕获
     */
    @ExceptionHandler(value = BaseException.class)
    public R handlerBusinessException(BaseException e) {
        return R.fail(e.getCode(),e.getMsg());
    }
}